import random
ip_dict=dict()
total_list=[]
ip_dict2=dict()

with open("ips","a+") as fp:
   for i in range(120000):             #写入ip
      ip_random=str(random.randint(1,254))
      fp.write("172.25.254.{}/24\n".format(ip_random))

with open("ips","r") as fp1:
   ip_list=fp1.readlines()
   ip_set=set(ip_list)
   for j in ip_set:
      total=ip_list.count(j)
      ip_dict[j]=total
      total_list.append(total)
   total_list.sort() #为ip地址出现次数进行排序

   for a in range(len(total_list)):
       for b in ip_dict.keys():
           if ip_dict[b]==total_list[a]:
               ip_dict2[b]=total_list[a]
           else:
               continue

   for f in range(10):  #统计出现频率前十的ip
       key=ip_dict2.popitem()   #反回的是一个元组
       print(f"{key[0]}出现了{key[1]}次")